﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using WMS6.Web.OrderMgtServiceRef;

    public class OrderMgtServiceClientProxy : BasePage
    {
        public string ClosePurchaseOrderInfo(List<string> poIDs)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.ClosePurchaseOrder(poIDs, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string ConvertSalesOrder2ShippingOrder(List<string> orderID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.ConvertSalesOrder2ShippingOrder(orderID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeletePurchaseOrderInfo(List<string> poIDs)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.DeletePurchaseOrder(poIDs, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteSalesOrderInfo(List<string> orderID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.DeleteSalesOrderInfo(orderID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public DataSet GetAllPurchaseOrderInfo()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                ds = client.GetAllInfoPurchaseOrder(pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public static OrderMgtServiceClientProxy GetInstance()
        {
            return new OrderMgtServiceClientProxy();
        }

        public PurchaseOrderInfo GetPurchaseOrderInfoByPoID(string poID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            PurchaseOrderInfo purchaseOrderInfo = null;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                purchaseOrderInfo = client.GetPurchaseOrderInfoByID(poID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return purchaseOrderInfo;
        }

        public DataSet GetPurchaseOrderInfoByQueryEntity(PurchaseOrderQueryEntity purchaseOrderQuery)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                ds = client.GetPurchaseOrderInfoByQueryEntity(purchaseOrderQuery, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetSalesOrderByQueryEntity(SalesOrderQueryEntity salesOrderQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                ds = client.GetSalesOrderByQueryEntity(salesOrderQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public SalesOrderInfo GetSalesOrderInfoByID(string salesOrderID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            SalesOrderInfo salesOrderInfo = null;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                salesOrderInfo = client.GetSalesOrderInfoByID(salesOrderID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return salesOrderInfo;
        }

        public SalesOrderInfo ImportSoByDataSet(DataSet ds)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            SalesOrderInfo salesOrderInfo = null;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                salesOrderInfo = client.ImportSoByDataSet(ds, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return salesOrderInfo;
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string InserOnLinePurchaseOrder(PurchaseOrderInfo purchaseOrderInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.InserOnLinePurchaseOrder(purchaseOrderInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertPurchaseOrderInfo(PurchaseOrderInfo purchaseOrderInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.InserPurchaseOrder(purchaseOrderInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertSalesOrderInfo(SalesOrderInfo salesOrderInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.InsertSalesOrderInfo(salesOrderInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string SalesOrderCancel(string orderID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.SalesOrderCancel(orderID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string TJConvertSalesOrder2ShippingOrder(List<string> orderID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.TJConvertSalesOrder2ShippingOrder(orderID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string TJInsertSalesOrderInfo(SalesOrderInfo salesOrderInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.TJInsertSalesOrderInfo(salesOrderInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string TJUpdateOnLineSO(SalesOrderInfo salesOrderInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.TJUpdateOnLineSO(salesOrderInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string TTConvertSalesOrder2ShippingOrder(List<string> orderID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.TTConvertSalesOrder2ShippingOrder(orderID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string TTInsertSalesOrderInfo(SalesOrderInfo salesOrderInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.TTInsertSalesOrderInfo(salesOrderInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string TTUpdateOnLineSO(SalesOrderInfo salesOrderInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.TTUpdateOnLineSO(salesOrderInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateOnLinePurchaseOrder(PurchaseOrderInfo purchaseOrderInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.UpdateOnLinePurchaseOrder(purchaseOrderInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateOnLineSO(SalesOrderInfo salesOrderInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.UpdateOnLineSO(salesOrderInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdatePurchaseOrderInfo(PurchaseOrderInfo purchaseOrderInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.UpdatePurchaseOrder(purchaseOrderInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateSalesOrderInfo(SalesOrderInfo salesOrderInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OrderMgtServiceClient client = new OrderMgtServiceClient("WSHttpBinding_IOrderMgtService");
            try
            {
                result = client.UpdateSalesOrderInfo(salesOrderInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }
    }
}

